#include "ExplosionManager.h"
#define MAX_EXPLOSION 20

CExplosionManager *CExplosionManager::_Instance = new CExplosionManager();

CExplosionManager::CExplosionManager(void)
{
}

CExplosionManager::~CExplosionManager(void)
{
}

CExplosionManager *CExplosionManager::GetInstance()
{
	return _Instance;
}

void CExplosionManager::LoadResources()
{
	for(int i =0; i < MAX_EXPLOSION; i++)
	{
		CExplosion *temp = new CExplosion();
		temp->LoadResources();
		_ExplosionPool.push(temp);
	}
}

void CExplosionManager::Explode(int X, int Y, int Level)
{
	if(_ExplosionPool.size() != 0)
	{
		CExplosion *temp = _ExplosionPool.front();
		temp->Explode(X, Y, Level);
		_ShowedExplosion.push_back(temp);
		_ExplosionPool.pop();
	}
}

void CExplosionManager::Render(D3DXVECTOR2 ContraPosition)
{
	for(int i = 0; i < _ShowedExplosion.size(); i++)
	{
		if(_ShowedExplosion[i]->CheckAlive())
		{
			_ShowedExplosion[i]->Render();
		}
		else
		{
			_ShowedExplosion[i]->Reset();
			_ExplosionPool.push(_ShowedExplosion[i]);
			_ShowedExplosion.erase(_ShowedExplosion.begin() + i);
		}
	}
}